package com.qushiyun.devops.admin.sync.data.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qushiyun.devops.admin.sync.data.mapper.DataSourceConfigMapper;
import com.qushiyun.devops.admin.sync.data.po.DataSourceConfig;
import com.qushiyun.devops.admin.sync.data.service.DataSourceConfigService;
import com.qushiyun.devops.common.framework.mybatis.page.vo.PageVO;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * DB Connection
 *
 * @author zhouzx
 */
@Service
public class DataSourceConfigServiceImpl extends ServiceImpl<DataSourceConfigMapper, DataSourceConfig> implements DataSourceConfigService {


    /**
     * 分页列表
     */
    @Override
    public PageVO<DataSourceConfig> pageList(PageDTO page, DataSourceConfig conn) {
        LambdaQueryWrapper<DataSourceConfig> wrapper = Wrappers.lambdaQuery(DataSourceConfig.class)
            .like(!StringUtils.isEmpty(conn.getName()), DataSourceConfig::getName, conn.getName());
        IPage<DataSourceConfig> pageResult = baseMapper.selectPage(page, wrapper);
        PageVO<DataSourceConfig> result = new PageVO<>();
        result.setTotal(pageResult.getTotal());
        result.setList(pageResult.getRecords());
        return result;
    }


}
